home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DClap / DPanel.h < prev    next >
Text File  |  1996-07-05  |  12KB  |  339 lines

  1. // DPanel.h
  2. // d.g.gilbert
  3.  
  4. #ifndef _DPANEL_
  5. #define _DPANEL_
  6.  
  7. #include "Dvibrant.h"
  8. #include "DView.h"
  9. #include "DFile.h"
  10. #include "DMethods.h"
  11. #include "DCommand.h"
  12.  
  13. class DScrollBar;
  14. class DTracker;
  15.  
  16. // DPanel is a general drawing area in a window (or in a view inside a window...)
  17. // User must subclass Draw() method to display something.
  18.  
  19. class DPanel : public DView
  20. {    
  21. public:
  22.     enum PanelKind { simple, autonomous, slatebound, subclasscreates };
  23.     Nlm_PaneL    fPanel;
  24.     PanelKind    fPanelKind;
  25.     Boolean        fMouseStillDown;
  26.     DTracker* fTracker;
  27.     
  28.     DPanel(long id, DView* itsSuperior, short pixwidth, short pixheight, PanelKind kind = simple);
  29.     virtual ~DPanel();
  30.  
  31.     virtual void Draw(void) = 0;
  32.     virtual void Scroll(Boolean vertical, DView* scrollee, long newval, long oldval);
  33.     void RegisterRect(Nlm_RecT r) { Nlm_RegisterRect(fPanel, &r); }
  34.     virtual void CharHandler(char c); // override stub, only for autonomous >> see class DKeyCallback instead
  35.     void SetSlateBorder(Boolean turnon);
  36.  
  37.         // mouse tracking
  38.     virtual void Click(Nlm_PoinT mouse);
  39.     virtual void Drag(Nlm_PoinT mouse);
  40.     virtual void Hold(Nlm_PoinT mouse);
  41.     virtual void Release(Nlm_PoinT mouse);
  42.     virtual void SetTracker( DTracker* mouseTracker);
  43.     virtual Nlm_Boolean IsDoneTracking();
  44.     virtual void TrackMouse( short aTrackPhase,
  45.                     Nlm_PoinT& anchorPoint, Nlm_PoinT& previousPoint,
  46.                     Nlm_PoinT& nextPoint,    Nlm_Boolean mouseDidMove);
  47.     virtual void TrackFeedback( short aTrackPhase,
  48.                     const Nlm_PoinT& anchorPoint, const Nlm_PoinT& previousPoint,
  49.                     const Nlm_PoinT& nextPoint, Nlm_Boolean mouseDidMove, Nlm_Boolean turnItOn);
  50. };
  51.  
  52.  
  53.  
  54. class DAutoPanel : public DPanel
  55. {    
  56. public:    
  57.     DAutoPanel(long id, DView* itsSuperior, short pixwidth, short pixheight,
  58.             Boolean hasVscroll, Boolean hasHscroll);
  59. };
  60.  
  61.  
  62.  
  63. // DSlate is mainly (?) a scrolling handler for DPanel.  See below & Vibrant docs
  64.  
  65. class DSlate : public DView
  66. {    
  67. public:
  68.     Nlm_SlatE    fSlate;
  69.     enum SlateKind { scrolling, normal, hidden, general };
  70.     DSlate(long id, DView* itsSuperior, short width, short height, SlateKind kind = normal);
  71.  
  72.     void VirtualSlate( short before, short after);
  73.  
  74.     void SetCharHandler(void);
  75.     virtual void CharHandler(char c); // override as needed
  76.  
  77.     void CaptureFocus(void) { Nlm_CaptureSlateFocus( fSlate); }
  78.         
  79.     DScrollBar* GetVScrollBar(void) {
  80.         return (DScrollBar*) Nlm_GetObject( (Nlm_GraphiC)Nlm_GetSlateVScrollBar(fSlate));
  81.         }
  82.     DScrollBar* GetHScrollBar(void) {
  83.         return (DScrollBar*) Nlm_GetObject( (Nlm_GraphiC)Nlm_GetSlateHScrollBar(fSlate));
  84.         }
  85.     
  86.     void SetSlateBorder(Boolean turnon) {    Nlm_SetSlateBorder(fSlate, turnon); }
  87.     
  88.     void RegisterRow( short position, short height, short count) {
  89.         Nlm_RegisterRow( fSlate, position, height, count);
  90.         }
  91.     void RegisterColumn( short position, short width, short count) {
  92.         Nlm_RegisterColumn( fSlate, position, width, count);
  93.         }
  94.  
  95. };
  96.  
  97.  
  98.  
  99.  
  100. class DNotePanel : public DPanel
  101. {    
  102.     Nlm_IcoN fIconBut;
  103.     char*        fText;
  104.     ulong    fTextLen;
  105.     Nlm_FonT fFont;
  106.     Justify    fJust;
  107.     Boolean    fEnabled, fDimmed;
  108. public:
  109.     DNotePanel(long id, DView* itsSuperior, const char* title, 
  110.             short pixwidth = 0, short pixheight = 0, Nlm_FonT font = Nlm_programFont, Justify just = justleft);
  111.     virtual void GetSize(short& width, short& height);
  112.     virtual void SetTitle(char* title);
  113.     virtual char* GetTitle(char* title = NULL, ulong maxsize = 256); 
  114.     virtual void Draw();
  115.     virtual void Click(Nlm_PoinT mouse);
  116.     virtual void Release(Nlm_PoinT mouse);
  117.     virtual void Invalid(short newval, short oldval);
  118.     virtual void Enable();    
  119.     virtual void Disable();
  120.     virtual void SetDim(Boolean isDim, Boolean redraw= false);  
  121. };
  122.  
  123.  
  124. class DIcon;
  125.  
  126. class DIconButton : public DPanel
  127. {    
  128. public:
  129.     Nlm_IcoN fIconBut;
  130.     DIcon*    fIcon;
  131.     Boolean    fEnabled;
  132.     
  133.     DIconButton(long id, DView* itsSuperior, DIcon* itsIcon);
  134.     virtual void Draw();
  135.     virtual void Click(Nlm_PoinT mouse);
  136.     virtual void Release(Nlm_PoinT mouse);
  137.     virtual void Invalid(short newval, short oldval);
  138.     virtual void SetIcon( DIcon* itsIcon, Boolean redraw = false);
  139.     void GetIconSize(short& pixwidth, short& pixheight);
  140.     virtual void Enable();    
  141.     virtual void Disable();
  142. };
  143.  
  144.  
  145. class DSlatePanel : public DPanel
  146. {
  147. public:
  148.     DSlatePanel(long id, DSlate* itsSuperior, short pixwidth, short pixheight):
  149.         DPanel(id, itsSuperior, pixwidth, pixheight, DPanel::slatebound) 
  150.         {}
  151. };
  152.  
  153.  
  154. class DDisplay : public DView    
  155. {
  156. public:
  157.     Nlm_DisplaY    fDisplay;  // Nlm_DisplaY == form of Nlm_Slate
  158.     enum DisplayKind    { normal, scrolling };
  159.     DDisplay(long id, DView* itsSuperior, short width, short height, 
  160.                      DisplayKind kind = scrolling);
  161. };
  162.  
  163.  
  164.  
  165.         // DDocPanel is Vibrant's newer DocumentPanel type (document.h)
  166. class DDocPanel : public DPanel, public DPrintHandler, public DSaveHandler
  167. {
  168. public:
  169.     Nlm_DoC    fDocpanel;
  170.     
  171.     DDocPanel(long id, DView* itsSuperior, short pixwidth, short pixheight);
  172.     ~DDocPanel();
  173.  
  174.     virtual void Draw(void) {}
  175.     
  176.     virtual void Print(void)    { 
  177.         Nlm_PrintDocument(fDocpanel); 
  178.         }
  179.     virtual void Save(DFile* f) { 
  180.         if (f) Nlm_SaveDocument(fDocpanel, f->fFile); 
  181.         } 
  182.  
  183.     virtual    char* DataToChar(Pointer ptr); // override to get below methods to draw.
  184.  
  185.     void  SetTabs( short tabstops) { Nlm_SetDocTabstops(fDocpanel, tabstops); }
  186.     
  187.     void     Append( Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  188.                         Nlm_FonT font = Nlm_programFont, Boolean docOwnsData = true);
  189.     void     Replace( short item, Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  190.                         Nlm_FonT font = Nlm_programFont, Boolean docOwnsData = true);
  191.     void     Insert( short item, Pointer data, short lines, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat,
  192.                         Nlm_FonT font = Nlm_programFont, Boolean docOwnsData = true);
  193.  
  194.     void    Delete( short item) {
  195.         Nlm_DeleteItem(fDocpanel, item);
  196.         }
  197.             
  198.     virtual char* GetText(short item, short row, short col) {
  199.         return Nlm_GetDocText(fDocpanel, item, row, col);
  200.         }
  201.     void     MapPoint( Nlm_PoinT pt, short& item, short& row, short& col, Nlm_RectPtr rct) {
  202.         Nlm_MapDocPoint(fDocpanel, pt, &item, &row, &col, rct);
  203.         }
  204.     void    GetStats( short& itemCount, short& lineCount) {
  205.          Nlm_GetDocParams(fDocpanel, &itemCount, &lineCount);
  206.         }
  207.     void    GetItemStats( short item, short& startsAt, short& rowCount, short& columnCount, short& lineHeight) {
  208.         Nlm_GetItemParams(fDocpanel,item, &startsAt, &rowCount, &columnCount, &lineHeight);
  209.         }
  210.     void    GetColStats( short item, short column, short& pixelPosition, short& pixelWidth, short& pixelInset, Justify& just) {
  211.         char justc;
  212.         Nlm_GetColParams(fDocpanel, item, column, &pixelPosition, &pixelWidth, &pixelInset, &justc);
  213.         just= (Justify)justc;
  214.         }
  215.     Boolean GetScrollStats( short& offset, short& firstShown, short& firstLine) {
  216.         return Nlm_GetScrlParams(fDocpanel, &offset, &firstShown, &firstLine);
  217.         }
  218.     void     SetData(void* data);
  219.     VoidPtr GetData(void) { 
  220.         return Nlm_GetDocData(fDocpanel); 
  221.         }
  222.  
  223.     virtual Boolean    IsVisible( short item, short& top, short& bottom, short& firstline) {
  224.         return Nlm_ItemIsVisible(fDocpanel, item, &top, &bottom, &firstline);
  225.         }
  226.             
  227.     void    Update( short from, short to) {
  228.         Nlm_UpdateDocument(fDocpanel, from, to);
  229.         }
  230.     void    AdjustScroll(void) {
  231.         Nlm_AdjustDocScroll(fDocpanel);
  232.         }
  233.     void    SetAutoAdjust( Boolean autoAdjust) {
  234.         Nlm_SetDocAutoAdjust(fDocpanel, autoAdjust);
  235.         }
  236.  
  237. };
  238.  
  239.  
  240. class DTextDocPanel : public DDocPanel
  241. {
  242. public:
  243.     
  244.     DTextDocPanel(long id, DView* itsSuperior, short pixwidth, short pixheight) :
  245.         DDocPanel( id, itsSuperior, pixwidth, pixheight)
  246.         {}    
  247.  
  248.     void     Append( char* text, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat, Nlm_FonT font = Nlm_programFont) 
  249.         {
  250.         Nlm_AppendText(fDocpanel, text, parFormat, colFormat, font);
  251.         }
  252.     void     Replace( short item, char* text, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat, Nlm_FonT font = Nlm_programFont) 
  253.         {
  254.         Nlm_ReplaceText(fDocpanel, item, text, parFormat, colFormat, font);
  255.         }
  256.     void     Insert( short item, char* text, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat, Nlm_FonT font = Nlm_programFont) 
  257.         {
  258.         Nlm_InsertText(fDocpanel, item, text, parFormat, colFormat, font);
  259.         }
  260.                         
  261.     void    ShowFile( char* filename, Nlm_FonT font = Nlm_programFont) {
  262.         Nlm_DisplayFile(fDocpanel, filename, font);
  263.         }
  264.     void    ShowFileFancy( char* filename, Nlm_ParPtr parFormat, Nlm_ColPtr colFormat, Nlm_FonT font = Nlm_programFont, short tabStops = 4) {
  265.         Nlm_DisplayFancy(fDocpanel, filename, parFormat, colFormat, font, tabStops);
  266.         }
  267. };
  268.  
  269.  
  270.  
  271.  
  272. #if 0
  273. // vibrant info on panel & slate
  274. /***  SIMPLE UNIVERSAL DRAWING OBJECT  ***/
  275.  
  276. /*
  277. *  A panel object is a rectangular box on a window that provides a universal
  278. *  drawing environment. Panels translate click actions and drawing requests
  279. *  to instance-specific procedures.  The SimplePanel and AutonomousPanel objects
  280. *  are autonomous in that they create a single object within a window or group.
  281. *  (The more general and complex slate/panel combinations are discussed in the
  282. *  next section.)  SetPanelClick assigns click, drag, hold and release callbacks
  283. *  to a given panel.  SimplePanels have only the minimum parameters to specify a
  284. *  panel, and it is expected that the specific application callbacks for click,
  285. *  draw, etc., will handle the entire behavior of the panel.
  286. *
  287. *  AutonomousPanels allow the creation of higher-level graphical objects that
  288. *  can function like built-in Vibrant control objects while allowing much fancier
  289. *  graphical display and manipulation.  The extra parameter specifies the number
  290. *  of extra bytes to be placed on top of the panel instance data, and the data
  291. *  can be accessed with SetPanelExtra and GetPanelExtra.  The reset callback is
  292. *  called via the Reset class function, and should be used to free any instance-
  293. *  specific allocated memory that may be pointed to in the extra data.  In order
  294. *  to override certain class functions (e.g., to allow SetTitle to apply to a
  295. *  particular autonomous panel), the classPtr function can point to a GphPrcs
  296. *  array (in static or heap memory).  Any function pointer that is not NULL will
  297. *  override the standard function.
  298. *
  299. *  The purpose of providing separate slates and panels (see next section) is to
  300. *  allow multiple independent panels to be placed in the same scrolling unit.
  301. *  The slate handles scrolling, and the individual panel children have their
  302. *  own click and draw callbacks.  Slates are distinguished internally from
  303. *  autonomous panels because their click through reset procedures are all NULL.
  304. */
  305.  
  306.  
  307. /***  GENERALIZED SCROLLABLE DRAWING OBJECT  ***/
  308.  
  309. /*
  310. *  A slate object is a rectangular box on a window that provides a universal
  311. *  drawing environment to its panel object children. Panels translate click
  312. *  actions and drawing requests to instance-specific procedures.  The parent
  313. *  slate must be notified of individual row and column pixel offsets, and of
  314. *  the corresponding row heights and column widths, in order for slate scroll
  315. *  bars to work automatically.  The panel must be notified of the actual size
  316. *  of its virtual rectangle.  The panel instance procedures should use the
  317. *  GetOffset procedure to determine the pixel offset for purposes of drawing
  318. *  and responding to clicks.  The VirtualSlate procedure allows specification
  319. *  of virtual scroll positions before and after the real scroll positions in
  320. *  a slate.  When the user drags the scroll bar thumb into a virtual area, the
  321. *  virtual action callback should be used to load new data into the slate.
  322. *  The GeneralSlate allows the specification of an alternative scroll bar
  323. *  callback procedure for a scrolling slate, as well as extra instance space
  324. *  and an overriding class function, in order to effectively have an autonomous
  325. *  scrolling panel.  The default scroll bar procedure should be sufficient
  326. *  for most situations.  Superimposed panels, or derivatives of panels, can be
  327. *  used to build complicated behaviors using simpler objects.
  328. */
  329.  
  330. /*
  331. *  The currently selected display object in the front window receives
  332. *  the output that is sent to the terminal file.
  333.     // Nlm_DisplaY is a form of Nlm_SlatE (see below)
  334. */
  335. #endif
  336.  
  337.  
  338. #endif
  339.